#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <fmt/format.h>
using namespace std;

// sstream include istringstream and ostringstream for string content operation

std::vector<std::string> split(const std::string &s, char delimiter, bool keepEmpty = false)
{
    std::vector<std::string> tokens;
    std::string token;
    std::istringstream tokenStream(s);
    while (getline(tokenStream, token, delimiter))
    {
        if (!token.empty() || keepEmpty)
        {
            tokens.push_back(token);
        }
    }
    return tokens;
}
void testSplit()
{
    std::string s{"this, is ,a,,test,string"};
    char delimiter = ',';
    std::vector<std::string> result = split(s, delimiter);
    for (const auto &part : result)
    {
        std::cout << "Non-empty: [" << part << "]\n";
    }
}
std::string join(std::vector<std::string> s, const std::string &delimiter)
{
    std::string result = std::accumulate(std::next(s.begin()), s.end(), s[0], [&](const std::string &a, const std::string &b) -> std::string
                                         { return a + delimiter + b; });
    return result;
}

void testJoin()
{
    std::vector<std::string> parts = {"This", "is", "a", "test"};
    std::string delimiter = ",";
    std::cout << join(parts, delimiter) << std::endl;
}
int main()
{
    // testSplit();
    testJoin();
    return 0;
}
